﻿Imports System.Web
Imports System.Web.SessionState
Imports System.Threading
Imports System.Globalization
Imports System.Net.Mail
Imports System.Diagnostics
Imports Emails


Public Class Global2
    Inherits System.Web.HttpApplication

    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)

        Application("OnlineUsers") = 0

    End Sub
    Sub Session_Start(ByVal Sender As Object, ByVal E As EventArgs)

        'Pocet online uzivatelu
        Application.Lock()
        Application("OnlineUsers") = CInt(Application("OnlineUsers")) + 1
        Application.UnLock()

        If Not Request.Cookies("otmData") Is Nothing Then
            'If a cookie exists, set the session-object with the data from the cookie.
            Session("MyCulture") = Server.HtmlEncode(Request.Cookies("otmData")("languagePref"))
        Else
            'If the cookie doen’t exist (user visits the website for the first time) set the session-object to the default value, in this case English. And ‘create the cookie.
            Session("MyCulture") = "cs-CZ"
            Dim aCookie As New HttpCookie("otmData")
            aCookie.Values("languagePref") = Session("MyCulture")
            aCookie.Expires = System.DateTime.Now.AddDays(21)
            Response.Cookies.Add(aCookie)
        End If
    End Sub

    Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
        'Pocet online uzivatelu
        Application.Lock()
        Application("OnlineUsers") = CInt(Application("OnlineUsers")) - 1
        Application.UnLock()
    End Sub

    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        Dim email As New Emails
        Dim odeslano As Boolean = False
        odeslano = email.OdesliMail(New MailAddress("mr.datel@gmail.com"), "Chyba na webu Horejsi.cz", Server.GetLastError.ToString)
    End Sub
End Class

